/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.AlwaysOnClusterBy;
/*     */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.account.Key.ServerBy;
/*     */ import com.zimbra.common.account.Key.UCServiceBy;
/*     */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.CliUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AlwaysOnCluster;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.UCService;
/*     */ import com.zimbra.cs.account.XMPPComponent;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestACLGrant
/*     */   extends TestACL
/*     */ {
/*  53 */   private static String TEST_CASE_NAME = "TestACLGrant-";
/*     */   
/*  55 */   private static String ACCOUNT_NAME = getEmailAddr(TEST_CASE_NAME + "account").toLowerCase();
/*  56 */   private static String CALENDAR_RESOURCE_NAME = getEmailAddr(TEST_CASE_NAME + "cr").toLowerCase();
/*  57 */   private static String COS_NAME = TEST_CASE_NAME + "cos".toLowerCase();
/*  58 */   private static String DISTRIBUTION_LIST_NAME = getEmailAddr(TEST_CASE_NAME + "dl").toLowerCase();
/*  59 */   private static String SUBDOMAIN_NAME = getSubDomainName(TEST_CASE_NAME + "domain").toLowerCase();
/*  60 */   private static String SERVER_NAME = TEST_CASE_NAME + "server".toLowerCase();
/*  61 */   private static String ALWAYSONCLUSTER_NAME = TEST_CASE_NAME + "alwaysOnCluster".toLowerCase();
/*  62 */   private static String UC_SERVICE_NAME = TEST_CASE_NAME + "ucservice".toLowerCase();
/*  63 */   private static String XMPP_COMPONENT_NAME = TEST_CASE_NAME + "xmppcomponent".toLowerCase();
/*  64 */   private static String ZIMLET_NAME = TEST_CASE_NAME + "zimlet".toLowerCase();
/*     */   
/*     */   private Account getAccount() throws ServiceException {
/*  67 */     Account acct = mProv.get(Key.AccountBy.name, ACCOUNT_NAME);
/*  68 */     if (acct == null)
/*  69 */       acct = mProv.createAccount(ACCOUNT_NAME, "test123", null);
/*  70 */     return acct;
/*     */   }
/*     */   
/*     */   private CalendarResource getCalendarResource() throws ServiceException {
/*  74 */     CalendarResource cr = mProv.get(Key.CalendarResourceBy.name, CALENDAR_RESOURCE_NAME);
/*  75 */     if (cr == null) {
/*  76 */       Map<String, Object> attrs = new HashMap();
/*  77 */       attrs.put("displayName", "CALENDAR_RESOURCE_NAME");
/*  78 */       attrs.put("zimbraCalResType", "Equipment");
/*  79 */       cr = mProv.createCalendarResource(CALENDAR_RESOURCE_NAME, "test123", attrs);
/*     */     }
/*  81 */     return cr;
/*     */   }
/*     */   
/*     */   private Cos getCos() throws ServiceException {
/*  85 */     Cos cos = mProv.get(Key.CosBy.name, COS_NAME);
/*  86 */     if (cos == null)
/*  87 */       cos = mProv.createCos(COS_NAME, null);
/*  88 */     return cos;
/*     */   }
/*     */   
/*     */   private DistributionList getDistributionList() throws ServiceException {
/*  92 */     DistributionList dl = mProv.get(Key.DistributionListBy.name, DISTRIBUTION_LIST_NAME);
/*  93 */     if (dl == null)
/*  94 */       dl = mProv.createDistributionList(DISTRIBUTION_LIST_NAME, new HashMap());
/*  95 */     return dl;
/*     */   }
/*     */   
/*     */   private Domain getDomain() throws ServiceException {
/*  99 */     Domain domain = mProv.get(Key.DomainBy.name, SUBDOMAIN_NAME);
/* 100 */     if (domain == null)
/* 101 */       domain = mProv.createDomain(SUBDOMAIN_NAME, new HashMap());
/* 102 */     return domain;
/*     */   }
/*     */   
/*     */   private Server getServer() throws ServiceException {
/* 106 */     Server server = mProv.get(Key.ServerBy.name, SERVER_NAME);
/* 107 */     if (server == null)
/* 108 */       server = mProv.createServer(SERVER_NAME, new HashMap());
/* 109 */     return server;
/*     */   }
/*     */   
/*     */   private AlwaysOnCluster getAlwaysOnCluster() throws ServiceException {
/* 113 */     AlwaysOnCluster cluster = mProv.get(Key.AlwaysOnClusterBy.name, ALWAYSONCLUSTER_NAME);
/* 114 */     if (cluster == null)
/* 115 */       cluster = mProv.createAlwaysOnCluster(ALWAYSONCLUSTER_NAME, new HashMap());
/* 116 */     return cluster;
/*     */   }
/*     */   
/* 119 */   private UCService getUCService() throws ServiceException { UCService ucService = mProv.get(Key.UCServiceBy.name, UC_SERVICE_NAME);
/* 120 */     if (ucService == null)
/* 121 */       ucService = mProv.createUCService(UC_SERVICE_NAME, new HashMap());
/* 122 */     return ucService;
/*     */   }
/*     */   
/*     */   private XMPPComponent getXMPPComponent() throws ServiceException {
/* 126 */     XMPPComponent xmppCpnt = mProv.get(Key.XMPPComponentBy.name, XMPP_COMPONENT_NAME);
/* 127 */     if (xmppCpnt == null) {
/* 128 */       Map<String, Object> attrs = new HashMap();
/* 129 */       attrs.put("zimbraXMPPComponentCategory", "whatever");
/* 130 */       attrs.put("zimbraXMPPComponentClassName", "whatever");
/* 131 */       attrs.put("zimbraXMPPComponentType", "whatever");
/* 132 */       xmppCpnt = mProv.createXMPPComponent(XMPP_COMPONENT_NAME, getDomain(), getServer(), attrs);
/*     */     }
/* 134 */     return xmppCpnt;
/*     */   }
/*     */   
/*     */   private Zimlet getZimlet() throws ServiceException {
/* 138 */     Zimlet zimlet = mProv.getZimlet(ZIMLET_NAME);
/* 139 */     if (zimlet == null) {
/* 140 */       Map<String, Object> attrs = new HashMap();
/* 141 */       attrs.put("zimbraZimletVersion", "1.0");
/* 142 */       zimlet = mProv.createZimlet(ZIMLET_NAME, attrs);
/*     */     }
/* 144 */     return zimlet;
/*     */   }
/*     */   
/*     */   private void doTargetTest(Account authedAcct, Account grantee, TargetType targetType, NamedEntry target, Right right, Set<TargetType> expected) throws ServiceException
/*     */   {
/* 149 */     Boolean good = null;
/*     */     try
/*     */     {
/* 152 */       grantRight(authedAcct, targetType, target, GranteeType.GT_USER, grantee, right, ALLOW);
/* 153 */       revokeRight(authedAcct, targetType, target, GranteeType.GT_USER, grantee, right, ALLOW);
/* 154 */       good = Boolean.TRUE;
/*     */     } catch (ServiceException e) {
/* 156 */       if (e.getCode().equals("service.INVALID_REQUEST")) {
/* 157 */         good = Boolean.FALSE;
/*     */       }
/*     */       else
/* 160 */         throw e;
/*     */     }
/* 162 */     if (expected.contains(targetType)) {
/* 163 */       assertEquals(Boolean.TRUE, good);
/*     */     } else {
/* 165 */       assertEquals(Boolean.FALSE, good);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doTargetTest(Account authedAcct, Account grantee, Right right, Set<TargetType> expected) throws ServiceException
/*     */   {
/* 171 */     doTargetTest(authedAcct, grantee, TargetType.account, getAccount(), right, expected);
/* 172 */     doTargetTest(authedAcct, grantee, TargetType.calresource, getCalendarResource(), right, expected);
/* 173 */     doTargetTest(authedAcct, grantee, TargetType.cos, getCos(), right, expected);
/* 174 */     doTargetTest(authedAcct, grantee, TargetType.dl, getDistributionList(), right, expected);
/* 175 */     doTargetTest(authedAcct, grantee, TargetType.domain, getDomain(), right, expected);
/* 176 */     doTargetTest(authedAcct, grantee, TargetType.server, getServer(), right, expected);
/* 177 */     doTargetTest(authedAcct, grantee, TargetType.alwaysoncluster, getAlwaysOnCluster(), right, expected);
/* 178 */     doTargetTest(authedAcct, grantee, TargetType.ucservice, getUCService(), right, expected);
/* 179 */     doTargetTest(authedAcct, grantee, TargetType.xmppcomponent, getXMPPComponent(), right, expected);
/* 180 */     doTargetTest(authedAcct, grantee, TargetType.zimlet, getZimlet(), right, expected);
/*     */     
/* 182 */     doTargetTest(authedAcct, grantee, TargetType.config, null, right, expected);
/* 183 */     doTargetTest(authedAcct, grantee, TargetType.global, null, right, expected);
/*     */   }
/*     */   
/*     */   public void testAccountRight() throws Exception {
/* 187 */     String testName = getTestName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 192 */     Account authedAcct = getSystemAdminAccount(getEmailAddr(testName, "authed"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 197 */     Account GA = createAdminAccount(getEmailAddr(testName, "GA"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 202 */     Set<TargetType> expected = new HashSet();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 207 */     expected.add(TargetType.account);
/* 208 */     expected.add(TargetType.calresource);
/* 209 */     expected.add(TargetType.dl);
/* 210 */     expected.add(TargetType.domain);
/* 211 */     expected.add(TargetType.global);
/*     */     
/*     */ 
/* 214 */     doTargetTest(authedAcct, GA, getRight("test-preset-account"), expected);
/*     */     
/*     */ 
/* 217 */     doTargetTest(authedAcct, GA, getRight("test-getAttrs-account"), expected);
/* 218 */     doTargetTest(authedAcct, GA, getRight(inlineRightGet(TargetType.account, "description")), expected);
/*     */     
/*     */ 
/* 221 */     doTargetTest(authedAcct, GA, getRight("test-setAttrs-account"), expected);
/* 222 */     doTargetTest(authedAcct, GA, getRight(inlineRightSet(TargetType.account, "description")), expected);
/*     */     
/*     */ 
/* 225 */     doTargetTest(authedAcct, GA, getRight("test-combo-account"), expected);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 230 */     expected.clear();
/* 231 */     expected.add(TargetType.account);
/* 232 */     expected.add(TargetType.cos);
/* 233 */     expected.add(TargetType.calresource);
/* 234 */     expected.add(TargetType.dl);
/* 235 */     expected.add(TargetType.domain);
/* 236 */     expected.add(TargetType.global);
/*     */     
/* 238 */     doTargetTest(authedAcct, GA, getRight("test-getAttrs-accountCos"), expected);
/* 239 */     doTargetTest(authedAcct, GA, getRight("test-setAttrs-accountCos"), expected);
/*     */     
/* 241 */     expected.clear();
/* 242 */     expected.add(TargetType.global);
/* 243 */     doTargetTest(authedAcct, GA, getRight("test-combo-account-cos-accountCos"), expected);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   static enum Result
/*     */   {
/* 261 */     GOOD, 
/*     */     
/*     */ 
/* 264 */     INVALID_REQUEST, 
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 270 */     PERM_DENIED;
/*     */     
/*     */     private Result() {}
/*     */   }
/*     */   
/*     */   private void doTestGrant(Account delegator, TargetType targetType, NamedEntry target, GranteeType delegateeType, NamedEntry delegatee, Right right, TestACL.AllowOrDeny allowOrDeny, Result expected)
/*     */     throws ServiceException
/*     */   {
/* 278 */     Result actual = null;
/*     */     
/*     */     try
/*     */     {
/* 282 */       grantRight(delegator, targetType, target, delegateeType, delegatee, right, allowOrDeny);
/* 283 */       actual = Result.GOOD;
/*     */     } catch (ServiceException e) {
/* 285 */       if (e.getCode().equals("service.INVALID_REQUEST")) {
/* 286 */         actual = Result.INVALID_REQUEST;
/* 287 */       } else if (e.getCode().equals("service.PERM_DENIED")) {
/* 288 */         actual = Result.PERM_DENIED;
/*     */       } else
/* 290 */         throw e;
/*     */     }
/* 292 */     assertEquals(expected, actual);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doTestRevoke(Account delegator, TargetType targetType, NamedEntry target, GranteeType delegateeType, NamedEntry delegatee, Right right, TestACL.AllowOrDeny allowOrDeny, Result expected)
/*     */     throws ServiceException
/*     */   {
/* 301 */     Result actual = null;
/*     */     
/*     */ 
/* 304 */     actual = null;
/*     */     try {
/* 306 */       revokeRight(delegator, targetType, target, delegateeType, delegatee, right, allowOrDeny);
/* 307 */       actual = Result.GOOD;
/*     */     } catch (ServiceException e) {
/* 309 */       if (e.getCode().equals("service.INVALID_REQUEST")) {
/* 310 */         actual = Result.INVALID_REQUEST;
/* 311 */       } else if (e.getCode().equals("service.PERM_DENIED")) {
/* 312 */         actual = Result.PERM_DENIED;
/*     */       } else
/* 314 */         throw e;
/*     */     }
/* 316 */     assertEquals(expected, actual);
/*     */   }
/*     */   
/*     */ 
/*     */   private void doTestDelegate(Account delegator, TargetType targetType, NamedEntry target, GranteeType delegateeType, NamedEntry delegatee, Right right, TestACL.AllowOrDeny allowOrDeny, Result expected)
/*     */     throws ServiceException
/*     */   {
/* 323 */     doTestGrant(delegator, targetType, target, delegateeType, delegatee, right, allowOrDeny, expected);
/* 324 */     doTestRevoke(delegator, targetType, target, delegateeType, delegatee, right, allowOrDeny, expected);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doTestDelegate(Account delegator, TargetType targetType, NamedEntry target, GranteeType delegateeType, NamedEntry delegatee, Right right, Result expected)
/*     */     throws ServiceException
/*     */   {
/* 333 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, right, ALLOW, expected);
/* 334 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, right, DENY, expected);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void doDelegatePartialRight(Account delegator, TargetType targetType, NamedEntry target, GranteeType delegateeType, NamedEntry delegatee, Result expectedHasDelegateRight)
/*     */     throws ServiceException
/*     */   {
/* 350 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight("test-preset-account"), ALLOW, expectedHasDelegateRight);
/* 351 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight("test-getAttrs-account"), ALLOW, expectedHasDelegateRight);
/* 352 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight("test-setAttrs-account"), ALLOW, expectedHasDelegateRight);
/* 353 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight(inlineRightGet(TargetType.account, "description")), ALLOW, expectedHasDelegateRight);
/* 354 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight(inlineRightSet(TargetType.account, "description")), ALLOW, expectedHasDelegateRight);
/*     */     Result expected;
/*     */     Result expected;
/* 357 */     if ((targetType == TargetType.domain) || (targetType == TargetType.global)) {
/* 358 */       expected = expectedHasDelegateRight;
/*     */     } else
/* 360 */       expected = Result.INVALID_REQUEST;
/* 361 */     doTestDelegate(delegator, targetType, target, delegateeType, delegatee, getRight("test-preset-domain"), ALLOW, expected);
/*     */   }
/*     */   
/*     */   public void testDelegate() throws Exception {
/* 365 */     String testName = getTestName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 370 */     Account sysAdmin = getSystemAdminAccount(getEmailAddr(testName, "authed"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 375 */     Account GA_DELEGATOR = createAdminAccount(getEmailAddr(testName, "GA_DELEGATOR"));
/* 376 */     Account GA_DELEGATEE = createAdminAccount(getEmailAddr(testName, "GA_DELEGATEE"));
/* 377 */     DistributionList GG_DELEGATEE = createAdminGroup(getEmailAddr(testName, "GG_DELEGATEE"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 382 */     String domainName = getSubDomainName(testName).toLowerCase();
/* 383 */     Domain TD = mProv.createDomain(domainName, new HashMap());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 388 */     Right right = getRight("test-combo-account-domain");
/*     */     
/*     */ 
/*     */ 
/* 392 */     grantDelegableRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATOR, right);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 397 */     DistributionList subTargetDl = createGroup("dl@" + domainName);
/* 398 */     Account subTargetAcct = createAccount("acct@" + domainName);
/* 399 */     Domain otherDomain = mProv.createDomain("other." + domainName, new HashMap());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 407 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, right, Result.GOOD);
/* 408 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_GROUP, GG_DELEGATEE, right, Result.GOOD);
/*     */     
/*     */ 
/* 411 */     doTestDelegate(GA_DELEGATOR, TargetType.dl, subTargetDl, GranteeType.GT_USER, GA_DELEGATEE, right, Result.INVALID_REQUEST);
/* 412 */     doTestDelegate(GA_DELEGATOR, TargetType.dl, subTargetDl, GranteeType.GT_GROUP, GG_DELEGATEE, right, Result.INVALID_REQUEST);
/* 413 */     doTestDelegate(GA_DELEGATOR, TargetType.account, subTargetAcct, GranteeType.GT_USER, GA_DELEGATEE, right, Result.INVALID_REQUEST);
/* 414 */     doTestDelegate(GA_DELEGATOR, TargetType.account, subTargetAcct, GranteeType.GT_GROUP, GG_DELEGATEE, right, Result.INVALID_REQUEST);
/*     */     
/*     */ 
/* 417 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, otherDomain, GranteeType.GT_USER, GA_DELEGATEE, right, Result.PERM_DENIED);
/* 418 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, otherDomain, GranteeType.GT_GROUP, GG_DELEGATEE, right, Result.PERM_DENIED);
/*     */     
/*     */ 
/* 421 */     doTestDelegate(GA_DELEGATOR, TargetType.global, null, GranteeType.GT_USER, GA_DELEGATEE, right, Result.PERM_DENIED);
/* 422 */     doTestDelegate(GA_DELEGATOR, TargetType.global, null, GranteeType.GT_GROUP, GG_DELEGATEE, right, Result.PERM_DENIED);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 428 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, Result.GOOD);
/* 429 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_GROUP, GG_DELEGATEE, Result.GOOD);
/*     */     
/*     */ 
/* 432 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.dl, subTargetDl, GranteeType.GT_USER, GA_DELEGATEE, Result.GOOD);
/* 433 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.dl, subTargetDl, GranteeType.GT_GROUP, GG_DELEGATEE, Result.GOOD);
/* 434 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.account, subTargetAcct, GranteeType.GT_USER, GA_DELEGATEE, Result.GOOD);
/* 435 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.account, subTargetAcct, GranteeType.GT_GROUP, GG_DELEGATEE, Result.GOOD);
/*     */     
/*     */ 
/* 438 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.domain, otherDomain, GranteeType.GT_USER, GA_DELEGATEE, Result.PERM_DENIED);
/* 439 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.domain, otherDomain, GranteeType.GT_GROUP, GG_DELEGATEE, Result.PERM_DENIED);
/*     */     
/*     */ 
/* 442 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.global, otherDomain, GranteeType.GT_USER, GA_DELEGATEE, Result.PERM_DENIED);
/* 443 */     doDelegatePartialRight(GA_DELEGATOR, TargetType.global, otherDomain, GranteeType.GT_GROUP, GG_DELEGATEE, Result.PERM_DENIED);
/*     */   }
/*     */   
/*     */   public void testDelegateNonDelegableRight() throws Exception
/*     */   {
/* 448 */     String testName = getTestName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 453 */     Account sysAdmin = getSystemAdminAccount(getEmailAddr(testName, "authed"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 458 */     Account GA_DELEGATOR = createAdminAccount(getEmailAddr(testName, "GA_DELEGATOR"));
/* 459 */     Account GA_DELEGATEE = createAdminAccount(getEmailAddr(testName, "GA_DELEGATEE"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 464 */     String domainName = getSubDomainName(testName).toLowerCase();
/* 465 */     Domain TD = mProv.createDomain(domainName, new HashMap());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 470 */     Right right = getRight("test-combo-account-domain");
/* 471 */     Right subRight = getRight("test-preset-account");
/* 472 */     Right anotherRight = getRight("test-preset-distributionlist");
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 479 */     grantDelegableRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATOR, right);
/* 480 */     grantRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATOR, subRight, ALLOW);
/* 481 */     grantRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATOR, anotherRight, ALLOW);
/*     */     
/*     */ 
/* 484 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, right, Result.PERM_DENIED);
/*     */     
/*     */ 
/* 487 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, subRight, Result.PERM_DENIED);
/*     */     
/*     */ 
/* 490 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, anotherRight, Result.PERM_DENIED);
/*     */     
/*     */ 
/* 493 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, getRight("test-preset-domain"), Result.GOOD);
/* 494 */     doTestDelegate(GA_DELEGATOR, TargetType.domain, TD, GranteeType.GT_USER, GA_DELEGATEE, getRight(inlineRightGet(TargetType.account, "description")), Result.GOOD);
/*     */   }
/*     */   
/*     */   public void testDelegateToNonAdmin() throws Exception {
/* 498 */     String testName = getTestName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 503 */     Account sysAdmin = getSystemAdminAccount(getEmailAddr(testName, "authed"));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 508 */     Account GA = createAccount(getEmailAddr(testName, "GA"));
/* 509 */     DistributionList GG = createGroup(getEmailAddr(testName, "GG"));
/*     */     
/*     */ 
/* 512 */     Account member = createAccount(getEmailAddr(testName, "member"));
/* 513 */     mProv.addMembers(GG, new String[] { member.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 518 */     String domainName = getSubDomainName(testName).toLowerCase();
/* 519 */     Domain TD = mProv.createDomain(domainName, new HashMap());
/* 520 */     Account TA = createAccount("acct@" + domainName);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 525 */     Right right = getRight("test-combo-account-domain");
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 530 */     doTestGrant(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA, right, DELEGABLE, Result.INVALID_REQUEST);
/* 531 */     doTestGrant(sysAdmin, TargetType.domain, TD, GranteeType.GT_GROUP, GG, right, DELEGABLE, Result.INVALID_REQUEST);
/*     */     
/*     */ 
/* 534 */     doTestRevoke(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA, right, DELEGABLE, Result.GOOD);
/* 535 */     doTestRevoke(sysAdmin, TargetType.domain, TD, GranteeType.GT_GROUP, GG, right, DELEGABLE, Result.GOOD);
/*     */     
/*     */ 
/* 538 */     makeAccountAdmin(GA);
/* 539 */     makeGroupAdmin(GG);
/*     */     
/*     */ 
/* 542 */     grantDelegableRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_USER, GA, right);
/* 543 */     grantDelegableRight(sysAdmin, TargetType.domain, TD, GranteeType.GT_GROUP, GG, right);
/*     */     
/*     */ 
/* 546 */     verify(GA, TA, getRight("test-preset-account"), null, ALLOW);
/*     */     
/*     */ 
/* 549 */     verify(member, TA, getRight("test-preset-account"), null, DENY);
/*     */     
/*     */ 
/* 552 */     makeAccountAdmin(member);
/* 553 */     verify(member, TA, getRight("test-preset-account"), null, ALLOW);
/*     */     
/*     */ 
/* 556 */     makeGroupNonAdmin(GG);
/*     */     
/* 558 */     flushAccountCache(member);
/* 559 */     verify(member, TA, getRight("test-preset-account"), null, DENY);
/*     */     
/*     */ 
/* 562 */     makeGroupAdmin(GG);
/*     */     
/* 564 */     flushAccountCache(member);
/* 565 */     verify(member, TA, getRight("test-preset-account"), null, ALLOW);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception
/*     */   {
/* 570 */     CliUtil.toolSetup("INFO");
/*     */     
/*     */ 
/* 573 */     TestUtil.runTest(TestACLGrant.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestACLGrant.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */